package com.lxj.database.user;

import java.util.ArrayList;

import com.lxj.model.Pic;
import com.lxj.model.UserInfo;


public class UserInfoObserver {

	private ArrayList<OnUserInfoListener> mListeners = new ArrayList<OnUserInfoListener>();
	private static UserInfoObserver mInstance = null;
	
	public static UserInfoObserver getInstance()
	{
		if(null == mInstance)
		{
			mInstance = new UserInfoObserver();
		}		
		return mInstance;
	}
	
	public void addObserver(OnUserInfoListener aOnUserInfoListener)
	{
		if(aOnUserInfoListener != null && !mListeners.contains(aOnUserInfoListener))
		{
			mListeners.add(aOnUserInfoListener);
		}
	}
	
	public void removeObserver(OnUserInfoListener aOnUserInfoListener)
	{
		if(aOnUserInfoListener != null && mListeners.contains(aOnUserInfoListener))
		{
			mListeners.remove(aOnUserInfoListener);
		}
	}

	public void OnUserNameChanged(int aUserID, String aNewName)
	{
		for(OnUserInfoListener t : mListeners)
		{
			t.OnUserNameChanged(aUserID, aNewName);
		}
	}
	
	public void OnUserAdd(UserInfo aNewUser)
	{
		for(OnUserInfoListener t : mListeners)
		{
			t.OnUserAdd(aNewUser);
		}
	}
	
	public void OnUserRemove(int aUserID)
	{
		for(OnUserInfoListener t : mListeners)
		{
			t.OnUserRemove(aUserID);
		}
	}
	
	public void OnUserAvatarChagend(int aUserID, Pic aNewPic)
	{
		for(OnUserInfoListener t : mListeners)
		{
			t.OnUserAvatarChagend(aUserID, aNewPic);
		}
	}
}
